import instence from "@/utils/axios/index";

// 获取文章列表
export const getPostListApi = (params: {
  page: number;
  limit: number;
  categoryId: number;
}) => {
  return instence.get<{ list: IPost[]; total: number }>("post", {
    params,
  });
};

// 获取分类
export const getCategoryListApi = () => {
  return instence.get<ICategory[]>("post/category");
};

// 新增
export const addPostApi = (data: { title: string }) => {
  return instence.post("post", data);
};

// 文章详情
export const getPostDetailApi = (id: number) => {
  return instence.get<IPost>(`post/${id}`);
};

// 阅读量统计
export const readCountApi = (id: number) => {
  return instence.get(`post/readNum`, { params: { id } });
};

// 点赞
export const supportApi = (id: number) => {
  return instence.get(`post/support`, { params: { id } });
};

// 取消点赞  post/cancelSupport
export const cancelSupportApi = (id: number) => {
  return instence.get(`post/cancelSupport`, { params: { id } });
};
